package io.input;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author mubei
 * @date 2021/12/3
 * @description
 */
public class FileReader_ {

    @Test()
    public void test1() {
        String filePath = "D:\\date\\distable\\practice\\code\\basic\\src\\main\\java\\io\\test.txt";
        FileReader reader = null;
        try {
            reader = new FileReader(filePath);
            char[] chars = new char[5];
            int readLength = 0;

            while((readLength = reader.read()) != -1) {
                System.out.print((char) readLength);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Test()
    public void test2() {

        String filePath = "D:\\date\\distable\\practice\\code\\basic\\src\\main\\java\\io\\test.txt";
        FileReader reader = null;
        try {
            reader = new FileReader(filePath);
            char[] chars = new char[5];
            int readLength = 0;

            while((readLength = reader.read(chars)) != -1) {
                System.out.print(new String(chars,0,readLength));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
